class MailboxRestoreEngine:
    def __init__(self, graph_client, storage):
        self.client = graph_client
        self.storage = storage
        
    def restore_mailbox(self, backup_id: str, target_user: str, conflict_policy: str = "skip"):
        """恢复邮箱数据"""
        encrypted_data = self.storage.retrieve(backup_id)
        decrypted = AESCipher().decrypt(encrypted_data)
        decompressed = zstd.decompress(decrypted)
        messages = json.loads(decompressed)
        
        batch = []
        for msg in messages:
            batch.append(self._build_restore_payload(msg))
            if len(batch) >= 500:
                self._submit_batch(target_user, batch, conflict_policy)
                batch = []
                
        if batch:
            self._submit_batch(target_user, batch, conflict_policy)
            
    def _submit_batch(self, user_id: str, batch: list, policy: str):
        """批量提交恢复请求"""
        payload = {
            "requests": [{
                "id": msg["id"],
                "method": "POST" if policy == "overwrite" else "PATCH",
                "url": f"/users/{user_id}/messages",
                "body": msg["content"]
            } for msg in batch]
        }
        
        response = self.client.make_request(
            "POST", 
            "$batch",
            data=payload
        )
        self._handle_batch_response(response)